import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_van_android/pages/discover_page.dart';
import 'package:flutter_van_android/pages/mine_page.dart';

import '../utils/router_manager.dart';

class HomePage extends StatefulWidget with RouterBridge<void> {
  const HomePage({super.key});

  @override
  State<StatefulWidget> createState() {
    return _HomePageState();
  }
}

class _HomePageState extends State<HomePage> {
  int _currentIndex = 0; // 当前选中的页面索引
  // 页面列表
  final List<Widget> _pages = [
    DiscoverPage(),
    Center(child: Text('搜索', style: TextStyle(fontSize: 24))),
    Center(child: Text('消息', style: TextStyle(fontSize: 24))),
    MinePage(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: _pages,
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.white,
        selectedItemColor: Colors.green,
        // 选中项字体和图标颜色
        unselectedItemColor: Colors.grey,
        // 未选中项字体和图标颜色
        currentIndex: _currentIndex,
        onTap: (int index) {
          setState(() {
            _currentIndex = index; // 更新当前索引
          });
        },
        items: [
          BottomNavigationBarItem(
            icon: Image.asset(
                _currentIndex == 0
                    ? 'assets/icons/icon_discover_selected.png'
                    : 'assets/icons/icon_discover_unselected.png',
                width: 30.w,
                height: 30.h),
            label: '发现',
          ),
          BottomNavigationBarItem(
            icon: Image.asset(
                _currentIndex == 1
                    ? 'assets/icons/icon_heard_selected.png'
                    : 'assets/icons/icon_heard_unselected.png',
                width: 30.w,
                height: 30.h),
            label: '关注',
          ),
          BottomNavigationBarItem(
            icon: Image.asset(
                _currentIndex == 2
                    ? 'assets/icons/icon_msg_selected.png'
                    : 'assets/icons/icon_msg_unselected.png',
                width: 30.w,
                height: 30.h),
            label: '消息',
          ),
          BottomNavigationBarItem(
            icon: Image.asset(
                _currentIndex == 3
                    ? 'assets/icons/icon_person_selected.png'
                    : 'assets/icons/icon_person_unselected.png',
                width: 30.w,
                height: 30.h),
            label: '我的',
          ),
        ],
      ),
    );
  }
}
